#include "stdafx.h"
#include "RhsTreeNode.h"
#include "ComputationalTreeNodeVisitor.h"

using CollabRC::Bot::AI::RhsTreeNode;
using CollabRC::Bot::AI::OperationTreeNode;
using CollabRC::Bot::AI::ComputationalTreeNode;

/**
 * @brief Creates a new RhsTreeNode from the specified branches
 * @param lhs the left hand side branch which will be discarded
 * @param rhs the right hand side branch which will be used in the computation
 */
RhsTreeNode::RhsTreeNode(const ComputationalTreeNode& lhs, const ComputationalTreeNode& rhs)
:OperationTreeNode(lhs,rhs),m_branch(&rhs)
{
}

/**
 * @brief Creates a new RhsTreeNode which uses the same branches as the specified operation
 * @param copy the operation from which to copy the branches
 */
RhsTreeNode::RhsTreeNode(const OperationTreeNode& copy)
:OperationTreeNode(copy),m_branch(NULL)
{
}

RhsTreeNode::~RhsTreeNode() { }

/** {@inheritDoc} */
float RhsTreeNode::PerformOperation(float lhs, float rhs) const
{
    lhs = lhs; // Avoid warnings for unused parameters
    return rhs;
}

/** {@inheritDoc} */
ComputationalTreeNode* RhsTreeNode::Clone() const
{
    if (m_branch)
        return m_branch->Clone();
    else
        return new RhsTreeNode(*this);
}

RhsTreeNode::Factory RhsTreeNode::factory;
/** @brief Creates and registers this OperationTreeNodeFactory */
RhsTreeNode::Factory::Factory()
{
    OperationTreeNode::RegisterOperationTreeNodeFactory(this);
}

/** {@inheritDoc} */
CollabRC::Bot::AI::ComputationalTreeNode* RhsTreeNode::Factory::Instantiate(const ComputationalTreeNode& lhs, const ComputationalTreeNode &rhs) const 
{
    return new RhsTreeNode(lhs, rhs);
}

/** {@inheritDoc} */
void RhsTreeNode::Accept(CollabRC::Bot::AI::ComputationalTreeNodeVisitor& visitor)
{
    visitor.Visit(*this);
}
